<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>全员通知</title>
</head>
<link href="/pages/common/layui/css/layui.css" rel="stylesheet" media="all">
<link href="/pages/console/css/commonStyle.css" rel="stylesheet">
<link href="/pages/console/css/fullPush.css" rel="stylesheet">
<body>
<!--展示当前路径-->
<div class="layui-row background_white visitPathDiv">
    <div class="visitPath"></div>
</div>
<div id="keyWordList">
    <div class="layui-card" style="padding-top: 15px;">
        <div class="layui-card-body">
            <div class="layui-form-item" style="padding-right: 40px;">
                <!-- 推送类型 -->
                <form class="layui-form" style="padding: 0px;">
                    <div class="layui-form-item">
                        <label class="layui-form-label">推送类型</label>
                        <div class="layui-input-block">
                            <select name="city" lay-verify="required" lay-filter="test" class="type">
                                <option value="-1"></option>
                                <option value="0">全员通知</option>
                                <option value="1">自定义URL推送</option>
                            </select>
                        </div>
                    </div>

                </form>

                <div id="url" style="margin-top: 20px">
                    <label class="layui-form-label">URL地址</label>
                    <div class="layui-input-block">
                        <input name="username" lay-verify="required" lay-reqtext="网址是必填项，岂能为空？"
                               placeholder="请输入http/https开头的正确网址" autocomplete="off" class="layui-input urlText"
                               type="text">
                    </div>
                </div>

                <!--<br>-->
                <div id="title" style="margin-top: 20px">
                    <label class="layui-form-label">消息标题</label>
                    <div class="layui-input-block">
                        <input name="username" lay-verify="required" lay-reqtext="消息标题是必填项，岂能为空？"
                               placeholder="请输入消息标题" autocomplete="off" class="layui-input titleText" type="text">
                    </div>
                </div>


                <!--<br>-->

                <div id="area" style="margin-top: 20px">
                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">消息内容</label>
                        <div class="layui-input-block">
                            <textarea placeholder="请输入内容" class="layui-textarea textArea"></textarea>
                        </div>
                    </div>
                </div>

                <div class="padding_upDown_space">
                    <div class="layui-input-block">
                        <button class="layui-btn fullBtn full-submit motif_button_style" lay-submit lay-filter="formDemo"
                                onclick="fullPush()">立即提交
                        </button>
                    </div>
                    <label class="push_explain">功能说明：本功能适合做新版本和广告的通知提醒，所有用户均会收到操作系统级的推送通知，但APP内部并无新消息。
                        自定义URL通知是用户点击收到的推送内容后会跳转到对应URL地址，比如app下载地址或其他。</label>
                </div>

            </div>

        </div>

    </div>

</div>


</body>
<script type="text/javascript" src="/pages/common/jquery/jquery.min.js"></script>
<script type="text/javascript" src="/pages/console/assets/xss-filters.1.2.7.min.js"></script>
<script type="text/javascript" src="/pages/common/layui/layui.all.js"></script>
<script type="text/javascript" src="/pages/assets/js/jquery.md5.js"></script>
<script type="text/javascript" src="./js/common.js"></script>
<script type="text/javascript" src="/pages/console/js/authorityManagement.js"></script>
<script>
    function fullPush() {
        var type = $(".type").val();
        var url = $(".urlText").val();
        var title = $(".titleText").val();
        var body = $(".textArea").val();
        if (-1 == type) {
            layer.msg("请选择推送类型");
            return;
        } else if (1 == type) {
            if (Common.isNil(url)) {
                layer.msg("请填写URL地址");
                return;
			}
		}

        if(!Common.isNil(url)){
            if(!CheckUrl(url)){
                layer.msg("请填写合法的URL地址");
                return;
			}
        }
        if(Common.isNil(title)){
            layer.msg("请填写标题");
            return;
        }
        if(Common.isNil(body)){
            layer.msg("请填写推送内容");
            return;
        }

		console.log( type + "   "+ url+"  "+ title+"  "+body)
        Common.invoke({
            url:request('/console/sendSysNotice'),
            data:{
              	type : type,
                url :url,
				title : title,
                body:body
            },
            success:function(result){
                if(result.resultCode==1){
                    layer.msg("发送成功",{"icon":1});
                    $(".urlText").val("")
                    $(".titleText").val("")
                    $(".textArea").val("")
                }else if(result.resultCode == 0){
                    layer.msg(result.resultMsg);
				}
            },
            error:function () {
				
            }
        })
    }
    layui.form.on('select(test)', function(data){
        console.log(data.elem); //得到select原始DOM对象
        console.log(data.value); //得到被选中的值
        console.log(data.othis); //得到美化后的DOM对象
		if(1 != data.value){
			$("#url").hide();
		}else{
            $("#url").show();
		}

    });

    function CheckUrl(str) {
        var RegUrl = new RegExp();
        RegUrl.compile("^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$");//jihua.cnblogs.com
        if (!RegUrl.test(str)) {
            return false;
        }
        return true;
    }

    $(function () {
        //调用父级页面的Js函数
        window.parent.getJointVisitPath();
    })
</script>
</html>